<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<base href="<{$B_Url}>" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>在线客服系统</title>
	<load href="__PUBLIC__/bootstrap/css/bootstrap.min.css" />
	<load href="__PUBLIC__/bootstrap/css/bootstrap-theme.min.css" /> 
	<load href="__PUBLIC__/bootstrap/js/jquery.min.js" />
	<load href="__PUBLIC__/bootstrap/js/bootstrap.min.js" /> 
    <script type="text/javascript" src="__PUBLIC__/index/js/jquery.form.js" ></script> 

</head>
<body>
<input type="hidden" id="openid" name="openid" value="{$openid}">
<nav class="navbar navbar-default">
	<div class="container-fluid"> 
		<div class="navbar-header"><h2 style="text-align: center; margin:0px; padding:0px; line-height:40px; font-size:18px;">客服列表</h2></div>
	</div>
</nav>
<div style="margin: 10px;">
	<div class="list-group" id="kflistbox">
		<a href="javascript:void(0)" class="list-group-item"><center>正在加载中...</center></a>
	</div>
</div>
<!--
kf_account kf_headimgurl   kf_id   kf_nick  kf_wx
-->

<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" ></script> 
<script language="javascript">
$(function(){
	$.getJSON('/index.php/Kefu/getonlinekf',function(obj){
		$('#kflistbox').html('');
		$.each(obj.d,function(i,d){
			var html = '<a href="javascript:void(0)" class="list-group-item ';
			if(d.online==2){ html += ' disabled '; }else{  html += ' lbtn ' ; }
			//html += '" d_val="'+d.kf_account+'" ><span class="glyphicon glyphicon-user"></span> 【'+d.kf_nick+'】('+d.kf_account+')';
			html += '" d_val="'+d.kf_account+'" ><span class="glyphicon glyphicon-user"></span> 【'+d.kf_nick+'】';
			if(d.online==2){ html += ' 【离线】 '; }else{  html += ' 【在线】 ' ; }
			html += '</a>';
			$('#kflistbox').append(html);
			initclick();
		});
	});

});

function initclick(){
	$('.list-group-item').unbind('click').click(function(){ 
		if($(this).hasClass('disabled')){ alert('客服不在线');  return false; }
		var url = '/index.php/Kefu/createconnect';
		var parm = {openid:$('#openid').val(),kf_account:$(this).attr('d_val')};
		$.post(url,parm,function(obj){ 
			if(obj.s){
				wx.closeWindow();
			}else{
				alert(obj.m);
			}
		},'json'); 
	});
}

</script>

</body>
</html>